package bigoo.peer.ride;

import java.io.Serializable;
import java.util.Date;

import bigoo.common.PeerInfo;

@SuppressWarnings("deprecation")
public class Request implements Serializable {
    
    public enum RequestState {
	DISCONNECTED, OPEN, ACCEPTED, WAITING, CONFIRMED;
    }

    private static final long serialVersionUID = 1L;
    private String requestID;
    private transient RequestState state;
    private String destination;
    private Date date;
    private PeerInfo peer;
    private String rideID;

    public Request(String requestID, String destination, Date date, String rideID, PeerInfo peer) {
	this.requestID = requestID;
	this.destination = destination;
	this.date = date;
	this.rideID = rideID;
	this.peer = peer;
    }

    public PeerInfo getPeer() {
        return peer;
    }

    public String getRequestID() {
	return requestID;
    }

    public RequestState getRequestState() {
	return state;
    }

    public String getRideID() {
        return rideID;
    }

    protected void setRequestState(RequestState state) {
	this.state = state;
    }

    @Override
    public String toString() {
	return requestID + "|"+  destination + "|" + date + "|" + peer.getPeerID();
    }

    @Override
    public boolean equals(Object obj) {
	if (obj instanceof Request) {
	    Request other = (Request) obj;
	    return (this.destination.equals(other.destination) &&
		    this.date.getDay() == other.date.getDay() &&
		    this.date.getMonth() == other.date.getMonth());
	} else {
	    return false;
	}
    }
    
    
    @Override
    public int hashCode() {
	return this.destination.hashCode() & date.getDay() & date.getMonth();
    }
}
